package org.inspiration.dudu.message.service.impl;

import lombok.RequiredArgsConstructor;
import org.inspiration.dudu.message.mapper.MessageMapper;
import org.inspiration.dudu.message.model.dto.MessageDTO;
import org.inspiration.dudu.message.model.entity.MessageEntity;
import org.inspiration.dudu.message.model.entity.SessionEntity;
import org.inspiration.dudu.message.model.vo.MessageVO;
import org.inspiration.dudu.message.model.vo.SessionVO;
import org.inspiration.dudu.message.service.MessageService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class MessageServiceImpl implements MessageService {
    private final MessageMapper messageMapper;

    @Override
    public MessageVO transToVO(MessageEntity messageEntity) {
        MessageVO messageVO = new MessageVO();
        BeanUtils.copyProperties(messageEntity, messageVO);
        return messageVO;
    }


    @Override
    public MessageEntity transToEntity(MessageDTO messageDTO) {
        MessageEntity messageEntity = new MessageEntity();
        BeanUtils.copyProperties(messageDTO, messageEntity);
        return messageEntity;
    }

    @Override
    public void save(MessageEntity messageEntity) {
        messageMapper.save(messageEntity);
    }

    @Override
    public List<MessageVO> getRecentMessages(Long fromUserId, Long toUserId, Integer pageNum, Integer pageSize) {
        return messageMapper.getRecentMessages(fromUserId, toUserId, (pageNum - 1) * pageSize, pageSize);
    }


}
